package com.masterclient.app.base;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.masterclient.app.R;

public class TipDialog extends Dialog {

    String title;
    String content;
    String confirm;
    int type;//1：有标题；2：无标题

    public TipDialog(@NonNull Context context, String content, String confirm, int type) {
        super(context, R.style.MyDialog);
        this.content = content;
        this.confirm = confirm;
        this.type = type;
    }

    public TipDialog(@NonNull Context context, String title, String content, String confirm, int type) {
        super(context, R.style.MyDialog);
        this.title = title;
        this.content = content;
        this.confirm = confirm;
        this.type = type;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_tip);

        View viewTitle = (View) findViewById(R.id.view_title);
        TextView tvTitle = (TextView) findViewById(R.id.tv_title);
        TextView tvContent = (TextView) findViewById(R.id.tv_content);
        TextView tvConfirm = (TextView) findViewById(R.id.tv_confirm);

        View viewNoTitle = (View) findViewById(R.id.view_no_title);
        TextView tvNoTitleContent = (TextView) findViewById(R.id.tv_no_title_content);
        TextView tvNoTitleConfirm = (TextView) findViewById(R.id.tv_no_title_confirm);

        if (type == 1) {
            viewTitle.setVisibility(View.VISIBLE);
            viewNoTitle.setVisibility(View.GONE);
            tvTitle.setText(title);
            tvContent.setText(content);
            tvConfirm.setText(confirm);
            tvConfirm.setOnClickListener(v -> dismiss());
        } else {
            viewNoTitle.setVisibility(View.VISIBLE);
            viewTitle.setVisibility(View.GONE);
            tvNoTitleContent.setText(content);
            tvNoTitleConfirm.setText(confirm);
            tvNoTitleConfirm.setOnClickListener(v -> dismiss());
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowParams);
    }
}
